#! /bin/bash
source .env

create_dir() {
  if [ "$1" = "" ]; then
    return
  fi

  if [ ! -d "$1" ]; then
    echo "create dir === $1"
    mkdir -p $1
  else
    echo "exist dir === $1"
  fi
  chmod 777 $1
}


while read -r line
do
  # $(echo $line | grep "#") = "" 获取不包含 # 的字符串(这是注释的标识)
  # $(echo $line | grep "DIR") != ""  获取包含 DIR 的字符串(这是注释的标识)
  if [[ $(echo $line | grep "_DIR") != "" ]] && [[ $(echo $line | grep "#") = "" ]]; then
    array=(${line//=/ })
    create_dir ${array[1]}
  fi
done < ./.env

# 初始化docker网络
docker_network=$(docker network ls | grep app_net)
echo "query network ${docker_network}"
if [ "$docker_network" == "" ]; then
  echo "create docker network app_net: $(docker network create --driver bridge app_net)"
fi